home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / msysjour / vol06 / 01 / kermit / wnkmsc.c < prev    next >
C/C++ Source or Header  |  1990-12-31  |  27KB  |  885 lines

  1. /*
  2.  * WNKMSC.C
  3.  *
  4.  * Windows Kermit dialog box routines
  5.  *
  6.  * Copyright (c) 1990 by
  7.  * William S. Hall
  8.  * 3665 Benton Street, #66
  9.  * Santa Clara, CA 95051
  10.  *
  11.  */
  12.  
  13. #define NOKANJI
  14. #define NOMINMAX
  15. #define NOATOM
  16. #define NOSOUND
  17. #include <windows.h>
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <string.h>    
  21. #include "ascii.h"
  22. #include "wnkerm.h"
  23. #include "wnkdlg.h"
  24.  
  25. #define MAXPATHLEN    128
  26. static char *defstring = "*.*";        /* default file type */
  27.  
  28. /* local function declarations */
  29. static    void    NEAR    krmProtocolInit(HWND hDlg);
  30. static    void    NEAR    krmProtocolSet(HWND hDlg);
  31. static    void    NEAR    krmPacketsInit(HWND hDlg);
  32. static    void    NEAR    krmPacketsSet(HWND hDlg);
  33. static    void    NEAR    krmSetCancelFlags(HWND hDlg);
  34. static    void    NEAR    krmSendFileInit(HWND hDlg);
  35. static    int    NEAR    krmCheckSelect(HWND hDlg);
  36. static    void    NEAR    krmGetSendFileList(HWND hDlg, LONG lParam);
  37. static    BOOL    NEAR    krmListSelect(HWND hDlg, LONG lParam);
  38. static    void    NEAR    krmListBoxOK(HWND hDlg, LONG lParam);
  39. static    void    NEAR    krmPathSelect(HWND hDlg, LONG lParam);
  40. static    int    NEAR    GetCheckedRadioButton(HWND hDlg, WORD start, WORD end);
  41. static  int    NEAR    GetComboboxSelection(HWND hDlg, WORD id, char * buffer);
  42. static    int    NEAR    GetComboboxIndex(HWND hDlg, int id);
  43. static  char*   NEAR    getnamestr(char *str, int len);
  44.  
  45. /*
  46.  * krmOpenDlgBox
  47.  *
  48.  * Open a modal dialog box
  49.  */
  50. int FAR krmOpenDlgBox(HWND hWnd, FARPROC fpProc, WORD boxnum)
  51. {
  52.  
  53.     FARPROC fp;
  54.     BOOL result;
  55.  
  56.   /* make a proc instance for the about box window function */
  57.     fp = MakeProcInstance(fpProc, Kermit.hInst);
  58.   /* create a modal dialog box */
  59.     result = DialogBox(Kermit.hInst, MAKEINTRESOURCE(boxnum),hWnd,fp);
  60.     FreeProcInstance(fp);
  61.     return result;
  62.  
  63. }
  64.  
  65. /*
  66.  * krmProtocol
  67.  *
  68.  * This dialog box sets general parameters affecting the
  69.  * Kermit protocol.
  70.  */
  71. BOOL FAR PASCAL krmProtocol(HWND hDlg, unsigned message, WORD wParam, LONG lParam)
  72. {
  73.     switch(message) {
  74.     case WM_INITDIALOG:
  75.     krmProtocolInit(hDlg);
  76.     break;
  77.  
  78.     case WM_COMMAND:
  79.         switch(wParam) {
  80.         case IDOK:
  81.             krmProtocolSet(hDlg);
  82.             EndDialog(hDlg, TRUE);
  83.             break;
  84.         case IDCANCEL:
  85.             EndDialog(hDlg, FALSE);
  86.             break;
  87.         default:
  88.             return FALSE;
  89.         }
  90.         break;
  91.     default:
  92.         return FALSE;
  93.     }
  94.     return TRUE;
  95. }
  96.  
  97. /*
  98.  * krmProtocolSet
  99.  *
  100.  * In response to values chosen by the user, this
  101.  * routine sets the various protocol data structures.
  102.  * If requested, values are saved to WIN.INI
  103.  */
  104. static void NEAR krmProtocolSet(HWND hDlg)
  105. {
  106.  
  107.     char szAppStr[80];
  108.     char szKeyStr[80];
  109.     char szValStr[80];
  110.  
  111.     KermParams.Bell = IsDlgButtonChecked(hDlg, IDD_KRM_BELL);
  112.     KermParams.Timer = IsDlgButtonChecked(hDlg, IDD_KRM_TIMER);
  113.     KermParams.DiscardPartialFile = IsDlgButtonChecked(hDlg, IDD_KRM_DISCARD);
  114.     KermParams.FileWarning = IsDlgButtonChecked(hDlg, IDD_KRM_FILEWARNING);
  115.     KermParams.verbose = IsDlgButtonChecked(hDlg, IDD_KRM_VERBOSE);
  116.  
  117.     KermParams.BlockCheckType = GetCheckedRadioButton(hDlg, 
  118.                     IDD_KRM_1BYTECHK,
  119.                     IDD_KRM_3BYTECHK)
  120.                 - IDD_KRM_1BYTECHK + 1;
  121.  
  122.     GetComboboxSelection(hDlg, IDD_KRM_RETRYLIMIT, szValStr);
  123.     KermParams.RetryLimit = atoi(szValStr);
  124.  
  125.     GetComboboxSelection(hDlg, IDD_KRM_SENDDELAY, szValStr);
  126.     KermParams.SendDelay = atoi(szValStr);
  127.  
  128.   /* user wants to save the values, so write them to WIN.INI */
  129.     if (IsDlgButtonChecked(hDlg, IDD_KRM_SAVE)) {
  130.     LoadString(Kermit.hInst,IDS_KRM_KERMIT,(LPSTR)szAppStr,sizeof(szAppStr));
  131.  
  132.         LoadString(Kermit.hInst, IDS_KRM_TIMER, szKeyStr, sizeof(szKeyStr));
  133.         itoa(KermParams.Timer, szValStr, 10);
  134.         WriteProfileString(szAppStr, szKeyStr, szValStr);
  135.  
  136.         LoadString(Kermit.hInst, IDS_KRM_VERBOSE, szKeyStr, sizeof(szKeyStr));
  137.         itoa(KermParams.verbose, szValStr, 10);
  138.         WriteProfileString(szAppStr, szKeyStr, szValStr);
  139.  
  140.         LoadString(Kermit.hInst, IDS_KRM_DISCARD, szKeyStr, sizeof(szKeyStr));
  141.         itoa(KermParams.DiscardPartialFile, szValStr, 10);
  142.         WriteProfileString(szAppStr, szKeyStr, szValStr);
  143.  
  144.         LoadString(Kermit.hInst, IDS_KRM_BELL, szKeyStr, sizeof(szKeyStr));
  145.         itoa(KermParams.Bell, szValStr, 10);
  146.         WriteProfileString(szAppStr, szKeyStr, szValStr);
  147.  
  148.         LoadString(Kermit.hInst, IDS_KRM_FILEWARN, szKeyStr, sizeof(szKeyStr));
  149.         itoa(KermParams.FileWarning, szValStr, 10);
  150.         WriteProfileString(szAppStr, szKeyStr, szValStr);
  151.  
  152.         LoadString(Kermit.hInst, IDS_KRM_BLOCKCHECKTYPE, szKeyStr, sizeof(szKeyStr));
  153.         itoa(KermParams.BlockCheckType, szValStr, 10);
  154.         WriteProfileString(szAppStr, szKeyStr, szValStr);
  155.  
  156.         LoadString(Kermit.hInst, IDS_KRM_RETRYLIMIT, szKeyStr, sizeof(szKeyStr));
  157.         itoa(KermParams.RetryLimit, szValStr, 10);
  158.         WriteProfileString(szAppStr, szKeyStr, szValStr);
  159.  
  160.         LoadString(Kermit.hInst, IDS_KRM_SENDDELAY, szKeyStr, sizeof(szKeyStr));
  161.         itoa(KermParams.SendDelay, szValStr, 10);
  162.         WriteProfileString(szAppStr, szKeyStr, szValStr);
  163.  
  164.     SendMessage((HWND)(-1), WM_WININICHANGE, 0, (LONG)(LPSTR)szAppStr);
  165.     }
  166. }
  167.  
  168. /*
  169.  * krmProtocolInit
  170.  *
  171.  * Initialize the Kermit protocol settings
  172.  * dialog box.
  173.  */
  174. static void NEAR krmProtocolInit(HWND hDlg)
  175. {
  176.     register int i;
  177.     char buf[80];
  178.  
  179.     CheckDlgButton(hDlg, IDD_KRM_BELL, KermParams.Bell);
  180.     CheckDlgButton(hDlg, IDD_KRM_TIMER, KermParams.Timer);
  181.     CheckDlgButton(hDlg, IDD_KRM_DISCARD, KermParams.DiscardPartialFile);
  182.     CheckDlgButton(hDlg, IDD_KRM_FILEWARNING, KermParams.FileWarning);
  183.     CheckDlgButton(hDlg, IDD_KRM_VERBOSE, KermParams.verbose);
  184.     CheckRadioButton(hDlg, IDD_KRM_1BYTECHK, IDD_KRM_3BYTECHK,
  185.                IDD_KRM_1BYTECHK + KermParams.BlockCheckType - 1);
  186.  
  187.     for (i = 1; i <= 63; i++)
  188.     SendDlgItemMessage(hDlg, IDD_KRM_RETRYLIMIT, CB_INSERTSTRING,
  189.                 -1, (LONG)(LPSTR)itoa(i, buf, 10));
  190.     SendDlgItemMessage(hDlg, IDD_KRM_RETRYLIMIT, CB_SELECTSTRING,
  191.             -1, (LONG)(LPSTR)itoa(KermParams.RetryLimit, buf, 10));
  192.                 
  193.     for (i = 0; i <= 63; i++)
  194.     SendDlgItemMessage(hDlg, IDD_KRM_SENDDELAY, CB_INSERTSTRING,
  195.                 -1, (LONG)(LPSTR)itoa(i, buf, 10));
  196.     SendDlgItemMessage(hDlg, IDD_KRM_SENDDELAY, CB_SELECTSTRING,
  197.             -1, (LONG)(LPSTR)itoa(KermParams.SendDelay, buf, 10));
  198. }
  199.  
  200. /*
  201.  * krmPackets
  202.  *
  203.  * This dialog box sets the various Kermit packet parameters.
  204.  */
  205. BOOL FAR PASCAL krmPackets(HWND hDlg, unsigned message, WORD wParam, LONG lParam)
  206. {
  207.     switch(message) {
  208.     case WM_INITDIALOG:
  209.     krmPacketsInit(hDlg);
  210.     break;
  211.  
  212.     case WM_COMMAND:
  213.         switch(wParam) {
  214.         case IDOK:
  215.             krmPacketsSet(hDlg);
  216.             EndDialog(hDlg, TRUE);
  217.             break;
  218.         case IDCANCEL:
  219.             EndDialog(hDlg, FALSE);
  220.             break;
  221.         default:
  222.             return FALSE;
  223.         }
  224.         break;
  225.     default:
  226.         return FALSE;
  227.     }
  228.     return TRUE;
  229. }
  230.  
  231. /*
  232.  * krmPacketsSet
  233.  *
  234.  * In response to values chosen by the user, this
  235.  * routine sets the various packet data structures.
  236.  * If requested, values are saved to WIN.INI
  237.  */
  238. static void NEAR krmPacketsSet(HWND hDlg)
  239. {
  240.     char szAppStr[80];
  241.     char szKeyStr[80];
  242.     char szValStr[80];
  243.  
  244.     sndparams.mark = (BYTE)GetComboboxIndex(hDlg, IDD_KRM_SENDMARK);
  245.     rcvparams.mark = (BYTE)GetComboboxIndex(hDlg, IDD_KRM_RECEIVEMARK);
  246.     sndparams.maxpktsize = (short)GetComboboxIndex(hDlg, IDD_KRM_SENDMAXSIZE)
  247.                + KRM_MINPACKETSIZE;
  248.     rcvparams.maxpktsize = (short)GetComboboxIndex(hDlg, IDD_KRM_RECEIVEMAXSIZE)
  249.                + KRM_MINPACKETSIZE;
  250.     sndparams.timeout = (short)GetComboboxIndex(hDlg, IDD_KRM_SENDTIMEOUT)
  251.                + KRM_MINTIMEOUT;
  252.     rcvparams.timeout = (short)GetComboboxIndex(hDlg, IDD_KRM_RECEIVETIMEOUT)
  253.                + KRM_MINTIMEOUT;
  254.     sndparams.padcount = (short)GetComboboxIndex(hDlg, IDD_KRM_SENDPADCOUNT);
  255.     rcvparams.padcount = (short)GetComboboxIndex(hDlg, IDD_KRM_RECEIVEPADCOUNT);
  256.     sndparams.padchar = (BYTE)GetComboboxIndex(hDlg, IDD_KRM_SENDPADCHAR);
  257.     if (sndparams.padchar >= ' ')
  258.     sndparams.padchar = DEL;
  259.     rcvparams.padchar = (BYTE)GetComboboxIndex(hDlg, IDD_KRM_RECEIVEPADCHAR);
  260.     if (rcvparams.padchar >= ' ')
  261.     sndparams.padchar = DEL;
  262.     sndparams.eol = (BYTE)GetComboboxIndex(hDlg, IDD_KRM_SENDEOL);
  263.     rcvparams.eol = (BYTE)GetComboboxIndex(hDlg, IDD_KRM_RECEIVEEOL);
  264.     sndparams.quote = (BYTE)(GetComboboxIndex(hDlg, IDD_KRM_SENDQUOTE) + '!');
  265.     if (sndparams.quote >= '?')
  266.     sndparams.quote += 30;
  267.     rcvparams.quote = (BYTE)(GetComboboxIndex(hDlg, IDD_KRM_RECEIVEQUOTE) + '!');
  268.     if (rcvparams.quote >= '?')
  269.     rcvparams.quote += 30;
  270.  
  271.     if (IsDlgButtonChecked(hDlg, IDD_KRM_SAVE)) {
  272.     LoadString(Kermit.hInst,IDS_KRM_KERMIT,(LPSTR)szAppStr,sizeof(szAppStr));
  273.  
  274.         LoadString(Kermit.hInst, IDS_KRM_SENDMARK, szKeyStr, sizeof(szKeyStr));
  275.         itoa(sndparams.mark, szValStr, 10);
  276.         WriteProfileString(szAppStr, szKeyStr, szValStr);
  277.  
  278.         LoadString(Kermit.hInst, IDS_KRM_RCVMARK, szKeyStr, sizeof(szKeyStr));
  279.         itoa(rcvparams.mark, szValStr, 10);
  280.         WriteProfileString(szAppStr, szKeyStr, szValStr);
  281.  
  282.         LoadString(Kermit.hInst, IDS_KRM_SENDMAXLEN, szKeyStr, sizeof(szKeyStr));
  283.         itoa(sndparams.maxpktsize, szValStr, 10);
  284.         WriteProfileString(szAppStr, szKeyStr, szValStr);
  285.  
  286.         LoadString(Kermit.hInst, IDS_KRM_RCVMAXLEN, szKeyStr, sizeof(szKeyStr));
  287.         itoa(rcvparams.maxpktsize, szValStr, 10);
  288.         WriteProfileString(szAppStr, szKeyStr, szValStr);
  289.  
  290.         LoadString(Kermit.hInst, IDS_KRM_SENDTIMEOUT, szKeyStr, sizeof(szKeyStr));
  291.         itoa(sndparams.timeout, szValStr, 10);
  292.         WriteProfileString(szAppStr, szKeyStr, szValStr);
  293.  
  294.         LoadString(Kermit.hInst, IDS_KRM_RCVTIMEOUT, szKeyStr, sizeof(szKeyStr));
  295.         itoa(rcvparams.timeout, szValStr, 10);
  296.         WriteProfileString(szAppStr, szKeyStr, szValStr);
  297.  
  298.         LoadString(Kermit.hInst, IDS_KRM_SENDPADCOUNT, szKeyStr, sizeof(szKeyStr));
  299.         itoa(sndparams.padcount, szValStr, 10);
  300.         WriteProfileString(szAppStr, szKeyStr, szValStr);
  301.  
  302.         LoadString(Kermit.hInst, IDS_KRM_RCVPADCOUNT, szKeyStr, sizeof(szKeyStr));
  303.         itoa(rcvparams.padcount, szValStr, 10);
  304.         WriteProfileString(szAppStr, szKeyStr, szValStr);
  305.  
  306.         LoadString(Kermit.hInst, IDS_KRM_SENDPADCHAR, szKeyStr, sizeof(szKeyStr));
  307.         itoa(sndparams.padchar, szValStr, 10);
  308.         WriteProfileString(szAppStr, szKeyStr, szValStr);
  309.  
  310.         LoadString(Kermit.hInst, IDS_KRM_RCVPADCHAR, szKeyStr, sizeof(szKeyStr));
  311.         itoa(rcvparams.padchar, szValStr, 10);
  312.         WriteProfileString(szAppStr, szKeyStr, szValStr);
  313.  
  314.         LoadString(Kermit.hInst, IDS_KRM_SENDEOL, szKeyStr, sizeof(szKeyStr));
  315.         itoa(sndparams.eol, szValStr, 10);
  316.         WriteProfileString(szAppStr, szKeyStr, szValStr);
  317.  
  318.         LoadString(Kermit.hInst, IDS_KRM_RCVEOL, szKeyStr, sizeof(szKeyStr));
  319.         itoa(rcvparams.eol, szValStr, 10);
  320.         WriteProfileString(szAppStr, szKeyStr, szValStr);
  321.  
  322.         LoadString(Kermit.hInst, IDS_KRM_SENDQUOTE, szKeyStr, sizeof(szKeyStr));
  323.         itoa(sndparams.quote, szValStr, 10);
  324.         WriteProfileString(szAppStr, szKeyStr, szValStr);
  325.  
  326.         LoadString(Kermit.hInst, IDS_KRM_RCVQUOTE, szKeyStr, sizeof(szKeyStr));
  327.         itoa(rcvparams.quote, szValStr, 10);
  328.         WriteProfileString(szAppStr, szKeyStr, szValStr);
  329.  
  330.     SendMessage((HWND)(-1), WM_WININICHANGE, 0, (LONG)(LPSTR)szAppStr);
  331.     }
  332. }
  333.  
  334. /*
  335.  * krmPacketsInit
  336.  *
  337.  * Initialize the Kermit packets settings
  338.  * dialog box.
  339.  */
  340. static void NEAR krmPacketsInit(HWND hDlg)
  341. {
  342.  
  343.     register int i;
  344.     char buf[80];
  345.  
  346.     for (i = 0; i < ' '; i++) {
  347.     sprintf(buf, "CTRL-%c", '@'+i);
  348.     SendDlgItemMessage(hDlg, IDD_KRM_SENDMARK, CB_INSERTSTRING,
  349.                -1, (LONG)(LPSTR)buf);
  350.     SendDlgItemMessage(hDlg, IDD_KRM_RECEIVEMARK, CB_INSERTSTRING,
  351.                -1, (LONG)(LPSTR)buf);
  352.     }
  353.     SendDlgItemMessage(hDlg,IDD_KRM_SENDMARK, CB_SETCURSEL,sndparams.mark, 0L);
  354.     SendDlgItemMessage(hDlg,IDD_KRM_RECEIVEMARK,CB_SETCURSEL,rcvparams.mark, 0L);
  355.  
  356.     for (i = KRM_MINPACKETSIZE; i <= KRM_MAXPACKETSIZE; i++) {
  357.     itoa(i, buf, 10);
  358.     SendDlgItemMessage(hDlg, IDD_KRM_SENDMAXSIZE, CB_INSERTSTRING,
  359.                -1, (LONG)(LPSTR)buf);
  360.     SendDlgItemMessage(hDlg, IDD_KRM_RECEIVEMAXSIZE, CB_INSERTSTRING,
  361.                -1, (LONG)(LPSTR)buf);
  362.     }
  363.     SendDlgItemMessage(hDlg,IDD_KRM_SENDMAXSIZE, CB_SETCURSEL,
  364.                sndparams.maxpktsize - KRM_MINPACKETSIZE, 0L);
  365.     SendDlgItemMessage(hDlg,IDD_KRM_RECEIVEMAXSIZE, CB_SETCURSEL,
  366.                rcvparams.maxpktsize - KRM_MINPACKETSIZE, 0L);
  367.  
  368.     for (i = KRM_MINTIMEOUT; i <= KRM_MAXTIMEOUT; i++) {
  369.     itoa(i, buf, 10);
  370.     SendDlgItemMessage(hDlg, IDD_KRM_SENDTIMEOUT, CB_INSERTSTRING,
  371.                -1, (LONG)(LPSTR)buf);
  372.     SendDlgItemMessage(hDlg, IDD_KRM_RECEIVETIMEOUT, CB_INSERTSTRING,
  373.                -1, (LONG)(LPSTR)buf);
  374.     }
  375.     SendDlgItemMessage(hDlg,IDD_KRM_SENDTIMEOUT, CB_SETCURSEL,
  376.                sndparams.timeout - KRM_MINTIMEOUT, 0L);
  377.     SendDlgItemMessage(hDlg,IDD_KRM_RECEIVETIMEOUT, CB_SETCURSEL,
  378.                rcvparams.timeout - KRM_MINTIMEOUT, 0L);
  379.  
  380.     for (i = 0; i <= KRM_MAXPADCOUNT; i++) {
  381.     itoa(i, buf, 10);
  382.     SendDlgItemMessage(hDlg, IDD_KRM_SENDPADCOUNT, CB_INSERTSTRING,
  383.                -1, (LONG)(LPSTR)buf);
  384.     SendDlgItemMessage(hDlg, IDD_KRM_RECEIVEPADCOUNT, CB_INSERTSTRING,
  385.                -1, (LONG)(LPSTR)buf);
  386.     }
  387.     SendDlgItemMessage(hDlg,IDD_KRM_SENDPADCOUNT,CB_SETCURSEL,
  388.                sndparams.padcount, 0L);
  389.     SendDlgItemMessage(hDlg,IDD_KRM_RECEIVEPADCOUNT,CB_SETCURSEL,
  390.                rcvparams.padcount, 0L);
  391.     for (i = 0; i < ' '; i++) {
  392.     sprintf(buf, "CTRL-%c", '@'+i);
  393.     SendDlgItemMessage(hDlg, IDD_KRM_SENDPADCHAR, CB_INSERTSTRING,
  394.                -1, (LONG)(LPSTR)buf);
  395.     SendDlgItemMessage(hDlg, IDD_KRM_RECEIVEPADCHAR, CB_INSERTSTRING,
  396.                -1, (LONG)(LPSTR)buf);
  397.     }
  398.     strcpy(buf, "CTRL ?");
  399.     SendDlgItemMessage(hDlg, IDD_KRM_SENDPADCHAR, CB_INSERTSTRING,
  400.                -1, (LONG)(LPSTR)buf);
  401.     SendDlgItemMessage(hDlg, IDD_KRM_RECEIVEPADCHAR, CB_INSERTSTRING,
  402.                -1, (LONG)(LPSTR)buf);
  403.     SendDlgItemMessage(hDlg,IDD_KRM_SENDPADCHAR,CB_SETCURSEL,
  404.                sndparams.padchar != DEL ? sndparams.padchar : 32, 0L);
  405.     SendDlgItemMessage(hDlg,IDD_KRM_RECEIVEPADCHAR,CB_SETCURSEL,
  406.                rcvparams.padchar != DEL ? rcvparams.padchar : 32, 0L);
  407.  
  408.     for (i = 0; i < 32; i++) {
  409.     sprintf(buf, "CTRL-%c", '@'+i);
  410.     SendDlgItemMessage(hDlg, IDD_KRM_SENDEOL, CB_INSERTSTRING,
  411.                -1, (LONG)(LPSTR)buf);
  412.     SendDlgItemMessage(hDlg, IDD_KRM_RECEIVEEOL, CB_INSERTSTRING,
  413.                -1, (LONG)(LPSTR)buf);
  414.     }
  415.     SendDlgItemMessage(hDlg,IDD_KRM_SENDEOL, CB_SETCURSEL,sndparams.eol, 0L);
  416.     SendDlgItemMessage(hDlg,IDD_KRM_RECEIVEEOL, CB_SETCURSEL,rcvparams.eol, 0L);
  417.  
  418.     for (i = 33; i <= 126; i++) {
  419.     if ((i >= 63) && (i <= 95))
  420.         continue;
  421.     sprintf(buf, "%c", i);
  422.     SendDlgItemMessage(hDlg, IDD_KRM_SENDQUOTE, CB_INSERTSTRING,
  423.                -1, (LONG)(LPSTR)buf);
  424.     SendDlgItemMessage(hDlg, IDD_KRM_RECEIVEQUOTE, CB_INSERTSTRING,
  425.                -1, (LONG)(LPSTR)buf);
  426.     }
  427.     SendDlgItemMessage(hDlg,IDD_KRM_SENDQUOTE, CB_SETCURSEL,
  428.             (33 <= sndparams.quote) && (sndparams.quote < 63) ? 
  429.             sndparams.quote - 33 : sndparams.quote - 63, 0L);
  430.     SendDlgItemMessage(hDlg,IDD_KRM_RECEIVEQUOTE, CB_SETCURSEL,
  431.             (33 <= rcvparams.quote) && (rcvparams.quote < 63) ? 
  432.             rcvparams.quote - 33 : rcvparams.quote - 63, 0L);
  433.     
  434. }
  435.  
  436. /* 
  437.  * krmSendFileProc
  438.  *
  439.  * This dialog box allows the user to choose a list of
  440.  * files to send to a remote Kermit.
  441.  */
  442. BOOL FAR PASCAL krmSendFileProc(HWND hDlg,unsigned message,WORD wParam,LONG lParam)
  443. {
  444.  
  445.     switch (message) {
  446.     case WM_INITDIALOG:
  447.         krmSendFileInit(hDlg);
  448.         break;
  449.  
  450.     case WM_COMMAND:
  451.         switch (wParam) {
  452.  
  453.         /* turn off SEND button if no files selected */
  454.         case IDD_KRM_LISTSELECT:
  455.             if (HIWORD(lParam) == LBN_SELCHANGE)
  456.             EnableWindow(GetDlgItem(hDlg, IDD_KRM_SEND),
  457.                       krmListSelect(hDlg, lParam));
  458.             break;
  459.  
  460.         /* in this dialog box, IDOK sets selections */
  461.         case IDOK:            
  462.             krmListBoxOK(hDlg, lParam);
  463.             EnableWindow(GetDlgItem(hDlg, IDD_KRM_SEND),
  464.                  krmListSelect(hDlg, lParam));
  465.             break;
  466.         
  467.         case IDCANCEL:
  468.             EndDialog(hDlg, FALSE);
  469.             break;
  470.  
  471.         /* get selected files into a buffer */
  472.         case IDD_KRM_SEND:
  473.             krmGetSendFileList(hDlg, lParam);
  474.             break;
  475.  
  476.         /* move to another directory */
  477.         case IDD_KRM_PATHSELECT:
  478.             krmPathSelect(hDlg, lParam);
  479.             break;
  480.  
  481.         default:
  482.             return FALSE;
  483.         }
  484.         break;
  485.  
  486.     default:
  487.         return FALSE;
  488.     }
  489.     return TRUE;
  490. }
  491.  
  492. /*
  493.  * krmListSelect
  494.  *
  495.  * Look through the file name list box for a selection.
  496.  */
  497. static BOOL NEAR krmListSelect(HWND hDlg, LONG lParam)
  498. {
  499.     BOOL select = FALSE;
  500.     register int i;
  501.     register int num = (int)SendDlgItemMessage(hDlg, IDD_KRM_LISTSELECT,
  502.                                 LB_GETCOUNT, 0, 0L);
  503.  
  504.     for (i = 0; i < num; i++) {
  505.     select = (BOOL)SendDlgItemMessage(hDlg, IDD_KRM_LISTSELECT, 
  506.                       LB_GETSEL, i, 0L);
  507.     if (select)
  508.         break;
  509.     }
  510.     return select;
  511. }
  512.  
  513. /*
  514.  * krmPathSelect
  515.  *
  516.  * Move to a new directory in the Send File dialog box.
  517.  */
  518. static void NEAR krmPathSelect(HWND hDlg, LONG lParam)
  519. {
  520.  
  521.     char buf[MAXPATHLEN];
  522.     char str[MAXPATHLEN];
  523.     int len;
  524.  
  525.     if (HIWORD(lParam) == LBN_SELCHANGE) {
  526.     len = GetDlgItemText(hDlg, IDD_KRM_EDITSELECT,(LPSTR)str,80);
  527.         DlgDirSelect(hDlg, (LPSTR)buf, IDD_KRM_PATHSELECT);
  528.     if (strchr(str,'*') || strchr(str,'?'))
  529.         strcat(buf,getnamestr(str,len));
  530.     else
  531.         strcat(buf, defstring);
  532.         SetDlgItemText(hDlg, IDD_KRM_EDITSELECT, (LPSTR)buf);
  533.     }
  534.     else if (HIWORD(lParam) == LBN_DBLCLK) {
  535.     GetDlgItemText(hDlg, IDD_KRM_EDITSELECT,(LPSTR)buf,80);
  536.     DlgDirList(hDlg, (LPSTR)buf, IDD_KRM_LISTSELECT,IDD_KRM_PATHDISPLAY, 0);
  537.     DlgDirList(hDlg, (LPSTR)buf, IDD_KRM_PATHSELECT,IDD_KRM_PATHDISPLAY, 0xC010);
  538.     SetDlgItemText(hDlg, IDD_KRM_EDITSELECT, (LPSTR)buf);
  539.     }
  540. }
  541.  
  542. /*
  543.  * krmSendFileInit
  544.  *
  545.  * Initialize the Send File Select dialog box
  546.  */
  547. static void NEAR krmSendFileInit(HWND hDlg)
  548. {
  549.  
  550.     char buf[10];
  551.     strcpy(buf, defstring);
  552.  
  553.     DlgDirList(hDlg, (LPSTR)buf, IDD_KRM_LISTSELECT,IDD_KRM_PATHDISPLAY, 0);
  554.     DlgDirList(hDlg, (LPSTR)buf, IDD_KRM_PATHSELECT,IDD_KRM_PATHDISPLAY, 0xC010);
  555.     SetDlgItemText(hDlg, IDD_KRM_EDITSELECT, (LPSTR)buf);
  556.     SendDlgItemMessage(hDlg, IDD_KRM_EDITSELECT,EM_LIMITTEXT,128,0L);
  557.     EnableWindow(GetDlgItem(hDlg, IDD_KRM_SEND), FALSE);
  558.  
  559. }
  560.  
  561. /*
  562.  * krmCheckSelect
  563.  *
  564.  * Count the number of files selected in the Send File Selection
  565.  * dialog box.
  566.  */
  567. static int NEAR krmCheckSelect(HWND hDlg)
  568. {
  569.  
  570.     register int num, i;
  571.     register int count = 0;
  572.  
  573.     num = (int)SendDlgItemMessage(hDlg, IDD_KRM_LISTSELECT,LB_GETCOUNT,0,0L);
  574.  
  575.     for (i = 0; i < num; i++)
  576.         if (SendDlgItemMessage(hDlg,IDD_KRM_LISTSELECT,LB_GETSEL,(WORD)i,0L))
  577.         count += 1;
  578.  
  579.     return count;
  580. }
  581.  
  582. /*
  583.  * krmGetSendFileList
  584.  *
  585.  * Read the list box for the names of the files selected
  586.  * to be sent by Kermit and store them in a locally allocated buffer
  587.  * as a single string delimited by spaces.
  588.  */
  589. static void NEAR krmGetSendFileList(HWND hDlg, LONG lParam)
  590. {
  591.  
  592.     char buf[MAXPATHLEN];
  593.     int count, i, num;
  594.  
  595.     count = krmCheckSelect(hDlg);
  596.     if (count > 0) {
  597.         Kermit.hFilelist = LocalAlloc(LPTR, count * 13);
  598.     if (Kermit.hFilelist != NULL) {
  599.         Kermit.pFilelist = LocalLock(Kermit.hFilelist);
  600.         num = (int)SendDlgItemMessage(hDlg, IDD_KRM_LISTSELECT,
  601.                         LB_GETCOUNT,0,0L);
  602.         for (i = 0; i < num; i++) {
  603.             if (SendDlgItemMessage(hDlg,IDD_KRM_LISTSELECT,LB_GETSEL,(WORD)i,0L)) {
  604.                    SendDlgItemMessage(hDlg, IDD_KRM_LISTSELECT,LB_GETTEXT, 
  605.                         (WORD)i, (LONG)(LPSTR)buf);
  606.             strcat(Kermit.pFilelist, buf);
  607.             strcat(Kermit.pFilelist, " ");
  608.             }
  609.             }
  610.         }
  611.         else
  612.         count = 0;
  613.     }
  614.     if (count == 0) {
  615.     /* no files selected or local alloc error */
  616.     }
  617.     EndDialog(hDlg,count);
  618. }
  619.  
  620. /*
  621.  * krmListBoxOK
  622.  *
  623.  * If user chooses the SELECT button (IDOK), highlight those files
  624.  * which match the specification in the associated edit select box.
  625.  * If nothing selected, remove all highlighting.
  626.  */
  627. static void NEAR krmListBoxOK(HWND hDlg, LONG lParam)
  628. {
  629.  
  630.     char buf[MAXPATHLEN];
  631.     int validsspec, count;
  632.     OFSTRUCT myoff;
  633.     int hfile;
  634.     char oldpath[MAXPATHLEN];
  635.     char *ptr;
  636.  
  637. /* if nothing in the edit box */
  638.     if (GetDlgItemText(hDlg, IDD_KRM_EDITSELECT,(LPSTR)buf,sizeof(buf)) == 0)
  639. /* remove highlighting from file list box */
  640.         SendDlgItemMessage(hDlg,IDD_KRM_LISTSELECT,LB_SETSEL,FALSE,(LONG)(-1));
  641.     else {
  642. /* otherwise, save the path */
  643.         GetDlgItemText(hDlg, IDD_KRM_PATHDISPLAY,(LPSTR)oldpath,128);
  644. /* see if valid search spec */
  645.     SendDlgItemMessage(hDlg, IDD_KRM_LISTSELECT, WM_SETREDRAW, FALSE, 0L);
  646.     SendDlgItemMessage(hDlg, IDD_KRM_PATHSELECT, WM_SETREDRAW, FALSE, 0L);
  647.     validsspec = DlgDirList(hDlg,(LPSTR)buf,IDD_KRM_LISTSELECT,IDD_KRM_PATHDISPLAY,0);
  648.     SendDlgItemMessage(hDlg, IDD_KRM_LISTSELECT, WM_SETREDRAW, TRUE, 0L);
  649.     SendDlgItemMessage(hDlg, IDD_KRM_PATHSELECT, WM_SETREDRAW, TRUE, 0L);
  650. /* if valid, get the new path */
  651.     if (validsspec) {
  652. /* buf modified, so update it */
  653.         SetDlgItemText(hDlg, IDD_KRM_EDITSELECT, (LPSTR)buf);
  654.         GetDlgItemText(hDlg, IDD_KRM_PATHDISPLAY, (LPSTR)buf, sizeof(buf));
  655. /* if the same as before */
  656.         if (strcmp(oldpath, buf) == 0)
  657. /* select the whole list box */
  658.                 SendDlgItemMessage(hDlg,IDD_KRM_LISTSELECT,
  659.                    LB_SETSEL,TRUE,(LONG)(-1));
  660.         else {
  661. /* update the directory change box */
  662.                 SendDlgItemMessage(hDlg,IDD_KRM_LISTSELECT,
  663.                    LB_SETSEL,FALSE,(LONG)(-1));
  664.             DlgDirList(hDlg,(LPSTR)buf,IDD_KRM_PATHSELECT,
  665.                IDD_KRM_PATHDISPLAY, 0xC010);
  666.         }
  667. /* not a valid search spec */
  668.     } else {
  669. /* clear box */
  670.             SendDlgItemMessage(hDlg, IDD_KRM_LISTSELECT, LB_RESETCONTENT,0,0L);
  671. /* see if it exists */
  672.         hfile = OpenFile((LPSTR)buf, (OFSTRUCT FAR *)&myoff, OF_EXIST);
  673.         if (hfile != -1) {
  674. /* get the file name and add it to list box */
  675.             ptr = strrchr(myoff.szPathName,'\\') + 1;
  676.             SendDlgItemMessage(hDlg, IDD_KRM_LISTSELECT,LB_ADDSTRING,0,
  677.                             (LONG)(LPSTR)ptr);
  678. /* get the pathname */
  679.             strcpy(buf, myoff.szPathName);
  680.             count = strlen(buf) - strlen(ptr);
  681.             buf[count] = NUL;
  682. /* select it */
  683.                 SendDlgItemMessage(hDlg,IDD_KRM_LISTSELECT,LB_SETSEL,TRUE,-1L);
  684. /* update the path select box */
  685.             SetDlgItemText(hDlg, IDD_KRM_EDITSELECT, (LPSTR)ptr);
  686.             DlgDirList(hDlg, (LPSTR)buf, IDD_KRM_PATHSELECT,IDD_KRM_PATHDISPLAY, 0xC010);
  687.         }
  688.         }
  689.     }
  690. /* select text in edit box */
  691.     SendDlgItemMessage(hDlg, IDD_KRM_EDITSELECT, EM_SETSEL, 0, MAKELONG(0,32767));
  692. }
  693.  
  694. /* 
  695.  * krmXferDlgBox
  696.  *
  697.  * Show the progress of the file transfer
  698.  */
  699. BOOL FAR PASCAL krmXferDlgBox(HWND hDlg,unsigned message,WORD wParam,LONG lParam)
  700. {
  701.  
  702.     char buf[40];
  703.     FARPROC fp;
  704.     register HWND hctl;
  705.  
  706.     switch (message) {
  707.  
  708.     case WM_INITDIALOG:
  709.         if (Kermit.mode == IDM_KRM_SEND) {
  710.                 LoadString(Kermit.hInst,IDS_KRM_SENDING, (LPSTR)buf, sizeof(buf));
  711.         SetDlgItemText(hDlg, IDD_KRM_OPERATION, (LPSTR)buf);
  712.         }
  713.         break;
  714.  
  715.     case WM_COMMAND:
  716.         switch (wParam) {
  717.         case IDCANCEL:
  718.             hctl = GetDlgItem(hDlg, IDCANCEL);
  719.             fp = MakeProcInstance((FARPROC)krmCancelBoxProc, Kermit.hInst);
  720.             DialogBox(Kermit.hInst,MAKEINTRESOURCE(DT_KRM_CANCEL),hDlg,fp);
  721.             FreeProcInstance(fp);
  722.             SetFocus(hctl);
  723.             break;
  724.  
  725.         default:
  726.             return FALSE;
  727.         }
  728.         break;
  729.  
  730.     default:
  731.         return FALSE;
  732.     }
  733.     return TRUE;
  734. }
  735.  
  736. /*
  737.  * krmCancelBoxProc
  738.  *
  739.  * Check the file transfer cancel mode
  740.  * and set the corresponding cancel flag
  741.  */
  742. BOOL FAR PASCAL krmCancelBoxProc(HWND hDlg, unsigned message,
  743.                  WORD wParam, LONG lParam)
  744. {
  745.  
  746.     switch (message) {
  747.     case WM_INITDIALOG:
  748.         CheckRadioButton(hDlg,IDD_KRM_CANCELFILE, IDD_KRM_CANCELPROTOCOL,
  749.                   IDD_KRM_CANCELFILE);
  750.         break;
  751.  
  752.     case WM_COMMAND:    /* system command */
  753.         switch (wParam) {
  754.  
  755.         case IDD_KRM_CANCELFILE:
  756.         case IDD_KRM_CANCELBATCH:
  757.         case IDD_KRM_CANCELERROR:
  758.         case IDD_KRM_CANCELPROTOCOL:
  759.             CheckRadioButton(hDlg, IDD_KRM_CANCELFILE, 
  760.                        IDD_KRM_CANCELPROTOCOL, wParam);
  761.             break;
  762.  
  763.         case IDOK:
  764.             krmSetCancelFlags(hDlg);
  765.             EndDialog(hDlg,TRUE);
  766.             break;
  767.  
  768.         case IDCANCEL:
  769.             EndDialog(hDlg, FALSE);
  770.             break;
  771.  
  772.         default:
  773.             return FALSE;    /* windows will handle this */
  774.         }
  775.         break;
  776.  
  777.     default:
  778.         return FALSE;    /* and, windows will process this as well */
  779.     }
  780.     return TRUE;        /* if we process message, return TRUE */
  781. }
  782.  
  783. /*
  784.  * krmSetCancelFlags
  785.  *
  786.  * Set the file transfer cancel flags
  787.  * chosen by the user
  788.  */
  789. static void NEAR krmSetCancelFlags(HWND hDlg)
  790. {
  791.     register int i;
  792.     register WORD param;
  793.  
  794.     for (i = IDD_KRM_CANCELFILE; i <= IDD_KRM_CANCELPROTOCOL; i++) {
  795.     if (SendDlgItemMessage(hDlg, i, BM_GETCHECK, 0, 0L)) {
  796.         switch(i) {
  797.         case IDD_KRM_CANCELFILE:
  798.             param = IDM_KRM_FILEABORT;
  799.             break;
  800.             case IDD_KRM_CANCELBATCH:
  801.             param = IDM_KRM_BATCHABORT;
  802.             break;
  803.         case IDD_KRM_CANCELERROR:
  804.             param = IDM_KRM_ERRORABORT;
  805.             break;
  806.         case IDD_KRM_CANCELPROTOCOL:
  807.             param = IDM_KRM_CANCEL;
  808.             break;
  809.         }
  810.         PostMessage(Kermit.hWnd, WM_COMMAND, param, 0L);
  811.         break;
  812.     }
  813.     }
  814. }
  815.  
  816. /*
  817.  * GetComboboxSelection
  818.  *
  819.  * Utility function for combo boxes
  820.  * Finds the highlighted string and returns its value.
  821.  *
  822.  */
  823. static int NEAR GetComboboxSelection(HWND hDlg, WORD id, char * buffer)
  824. {
  825.     register int index;
  826.  
  827.     index = (int)SendDlgItemMessage(hDlg, id, CB_GETCURSEL, 0, 0L);
  828.     if (index != CB_ERR)
  829.     index = (int)SendDlgItemMessage(hDlg, id, CB_GETLBTEXT,
  830.                     index, (LONG)(LPSTR)buffer);
  831.     return index;
  832. }
  833.  
  834. /*
  835.  * GetComboBoxIndex
  836.  *
  837.  * Utility function for combo boxes
  838.  * Get the index of the current selection
  839.  */
  840. static int NEAR GetComboboxIndex(HWND hDlg, int id)
  841. {
  842.     return (int)SendDlgItemMessage(hDlg, id, CB_GETCURSEL, 0, 0L);
  843. }
  844.  
  845. /*
  846.  * GetChecked RadioButton
  847.  *
  848.  * Utility function for radio buttons
  849.  * Finds the checked button, if any, in a group
  850.  * of radio buttons.  If none, then returns highest value
  851.  * of the range plus 1
  852.  */
  853. static int NEAR GetCheckedRadioButton(HWND hDlg, WORD start, WORD end)
  854. {
  855.  
  856.     register WORD i;
  857.  
  858.     for (i = start; i <= end; i++)
  859.     if (SendDlgItemMessage(hDlg, i, BM_GETCHECK, 0, 0L))
  860.         break;
  861.  
  862.     return i;
  863. }
  864.  
  865. /*
  866.  * getnamestr
  867.  *
  868.  * Utility function to parse a path name for a file name
  869.  */
  870. static char* NEAR getnamestr(char *str, int len)
  871. {
  872.     char *tmp;
  873.  
  874.     tmp = str + len;
  875.  
  876.     while ((*tmp != ':') && (*tmp != '\\') && (tmp > str))
  877.     tmp--;
  878.     if (*tmp != ':' && *tmp != '\\')
  879.     return(tmp);
  880.     else
  881.     return(tmp + 1);
  882.  
  883. }
  884.  
  885.